import { Component, OnInit } from '@angular/core';
import { JsonApiService } from "app/core/api/json-api.service"; //http请求配置引入
import { Router } from "@angular/router"; //路由引入

@Component({
	selector: 'sa-param-file',
	templateUrl: './param-file.component.html',
})
export class ParamFileComponent implements OnInit {
	tableData: any[] = []; //table数据
	totalCount: number = 0; //分页总条数
	curPage: number = 1; //分页当前页
	pageSize: number = 10; //内置的分页每页条数
	searchKey: string = ''; //搜索keyword
	selectedRow: boolean = false;

	constructor(private jsonApiService: JsonApiService, private router: Router) {}

	ngOnInit() {
		this.load();
	}
	//刷新
	refresh() {
		this.load();
	}
	//表格搜索
	table_search(word) {
		this.curPage = 1
		this.searchKey = common.stringTrim(this.searchKey);
		this.load();
	}
	//初始化加载list数据
	load() {
		let reqdata = 'gridPager={"pageSize":' + this.pageSize + ',"nowPage":' + this.curPage + ',"parameters":{"searchKey":"' + this.searchKey + '"}}'
		this.jsonApiService.http("experiment/bluetoothlist.html", reqdata).subscribe(data => {
			this.tableData = data.exhibitDatas;
			this.totalCount = data.recordCount;
		})
	}
	//分页回调
	paginate(e) {
		this.curPage = e.page + 1;
		this.pageSize = e.rows;
		this.load();
	}
	//文件上传
	up_file(type) {
		if(type === 'new') {
			this.router.navigate(['/data-management/param-file/param-file-page'], {
				queryParams: {
					type: 'new'
				}
			});
		}
	}
	//删除文件
	del_file(row) {
		this.jsonApiService.confirm_message("此操作将永久删除数据,确认要删除?").then(() => {
			let reqdata = 'deviceId=' + row.deviceId;
			this.jsonApiService.http("experiment/deleteBatch.html", reqdata).subscribe(data => {
				this.jsonApiService.message(data.message);
				if(data.success) {
					this.load();
				}
			})
		})
	}
}